﻿namespace Cellfish.Toolbox.Facts.Streams
{
    using System;
    using System.IO;

    using Cellfish.Test;
    using Cellfish.Toolbox.Streams;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class BlackHoleStreamFacts
    {
        private readonly BlackHoleStream blackHole = new BlackHoleStream();

        [TestMethod]
        public void Given_BlackHoleStream_When_reading_Then_all_requested_byte_count_is_returned()
        {
            Assert.IsTrue(this.blackHole.CanRead);
            Assert.AreEqual(int.MaxValue, this.blackHole.Read(null, 0, int.MaxValue));
        }

        [TestMethod]
        public void Given_BlackHoleStream_When_writing_Then_data_is_allowed()
        {
            Assert.IsTrue(this.blackHole.CanWrite);
            this.blackHole.Write(null, 0, int.MaxValue);
            this.blackHole.Flush();
        }

        [TestMethod]
        public void Given_BlackHoleStream_When_seeking_Then_NotSupportedException_is_thrown()
        {
            Assert.IsFalse(this.blackHole.CanSeek);
            Ensure.Throws<NotSupportedException>(() => { var p = this.blackHole.Position; }, "Did not fail in getting position.");
            Ensure.Throws<NotSupportedException>(() => { this.blackHole.Position = 0; }, "Did not fail in setting position.");
            Ensure.Throws<NotSupportedException>(() => this.blackHole.Seek(42, SeekOrigin.Current), "Did not fail in seeking.");
        }

        [TestMethod]
        public void Given_BlackHoleStream_When_working_with_length_Then_NotSupportedException_is_thrown()
        {
            Ensure.Throws<NotSupportedException>(() => { var p = this.blackHole.Length; }, "Did not fail in getting length.");
            Ensure.Throws<NotSupportedException>(() => this.blackHole.SetLength(42), "Did not fail in setting length.");
        }
    }
}
